package com.baixiaowen.xiaoaointerview.Java编程功底篇.手写栈_队列相关算法;

import java.util.LinkedList;

/**
 *
 * 基于LinkedList实现的队列
 *
 * @author Baixiaowen
 */
public class Queue<T> {

    LinkedList<T> list = new LinkedList<>();

    public void enqueue(T e) {
        list.add(e);
    }

    public T dequeue() {
        return list.remove();
    }

    public int size() {
        return list.size();
    }

    @Override
    public String toString() {
        return list.toString();
    }

    public static void main(String[] args) {
        Queue<Integer> queue = new Queue<>();

        queue.enqueue(1);
        queue.enqueue(2);
        queue.enqueue(3);
        queue.enqueue(4);

        for (int i = 0; i < queue.size(); i++) {
            if (i + 1 != queue.dequeue()) {
                System.err.println("成功");
            }
        }
    }
}
